﻿Imports System.Collections.Generic
Imports System.Data.SqlClient
Namespace QuanLyKhachHang
    Public Class ThongKeDoangThuDAL
        Public Function ThongKeDoanhThu_DanhSachKhachHang(ByVal TrangThai As String, ByVal BatDau As Integer, ByVal KetThuc As Integer, ByVal TypeSearch As String, ByVal KhachHangId As Integer, ByVal TenKhachHang As String) As List(Of TKDT_DanhSachKhachHang)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@BatDau", BatDau)
                SQLHelper.AddParameter("@KetThuc", KetThuc)
                SQLHelper.AddParameter("@TypeSearch", TypeSearch)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@TenKhachHang", TenKhachHang)
                Reader = SQLHelper.ExecuteReader("spThongKeDoanhThu_DanhSachKhachHang", CommandType.StoredProcedure)
                Dim item As TKDT_DanhSachKhachHang
                Dim list As New List(Of TKDT_DanhSachKhachHang)
                While (Reader.Read())
                    item = New TKDT_DanhSachKhachHang
                    item.TenNguoiMua = Reader("TenNguoiMua").ToString()
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.KhachHangID = Integer.Parse(Reader("KhachHangID").ToString())
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.MaTinhThanh = Reader("MaTinhThanh").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Function ThongKeDoanhThu_DanhSachDonHang_Mua(ByVal TrangThai As String, ByVal KhachHangId As Integer, ByVal BatDau As Integer, ByVal KetThuc As Integer, ByVal TenNguoiMua As String, ByVal DiaChi As String) As List(Of TKDT_DanhSachDonHang_Mua)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@BatDau", BatDau)
                SQLHelper.AddParameter("@KetThuc", KetThuc)
                SQLHelper.AddParameter("@TenNguoiMua", TenNguoiMua)
                SQLHelper.AddParameter("@DiaChi", DiaChi)
                Reader = SQLHelper.ExecuteReader("spThongKeDoanhThu_DanhSachDonHang_Mua", CommandType.StoredProcedure)
                Dim item As TKDT_DanhSachDonHang_Mua
                Dim list As New List(Of TKDT_DanhSachDonHang_Mua)
                While (Reader.Read())
                    item = New TKDT_DanhSachDonHang_Mua
                    item.IDDonHangBan = Integer.Parse(Reader("IDDonHangBan").ToString())
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.MaSoThue = Reader("MaSoThue").ToString()
                    item.NgayBan = Reader("NgayBan").ToString()
                    item.So = Reader("So").ToString()
                    item.HinhThucTiepThi = Reader("HinhThucTiepThi").ToString()
                    item.NhanVienTiepThi = Reader("NhanVienTiepThi").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Function ThongTinTiepThi(ByVal IDDonHangBan As Integer) As Object
            Try
                Dim SQLHelper As New SQLDataHelper
                SQLHelper.AddParameter("@IDDonHangBan", IDDonHangBan)
                Return SQLHelper.ExecuteScalar("spThongTinTiepThi", CommandType.StoredProcedure)
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Function ThongKeDoanhThu_DanhSachDonHang_DaiLy(ByVal TrangThai As String, ByVal KhachHangId As Integer, ByVal BatDau As Integer, ByVal KetThuc As Integer) As List(Of TKDT_DanhSachDonHang_DaiLy)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@BatDau", BatDau)
                SQLHelper.AddParameter("@KetThuc", KetThuc)
                Reader = SQLHelper.ExecuteReader("spThongKeDoanhThu_DanhSachDonHang_DaiLy", CommandType.StoredProcedure)
                Dim item As TKDT_DanhSachDonHang_DaiLy
                Dim list As New List(Of TKDT_DanhSachDonHang_DaiLy)
                While (Reader.Read())
                    item = New TKDT_DanhSachDonHang_DaiLy
                    item.IDDonHangBan = Integer.Parse(Reader("IDDonHangBan").ToString())
                    item.TiepThiChoKhachHang = Reader("TiepThiChoKhachHang").ToString()
                    item.TenNguoiMua = Reader("TenNguoiMua").ToString()
                    item.TenKhachHang = Reader("TenKhachHang").ToString()
                    item.DiaChi = Reader("DiaChi").ToString()
                    item.MaSoThue = Reader("MaSoThue").ToString()
                    item.NgayBan = Reader("NgayBan").ToString()
                    item.So = Reader("So").ToString()
                    item.HinhThucTiepThi = Reader("HinhThucTiepThi").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function
        Public Function ThongKeDoanhThu_KhachHang(ByVal KhachHangId As Integer, ByVal TrangThai As String, ByVal LoaiPhi As String, ByVal BatDau As Integer, ByVal KetThuc As Integer, ByVal TenNguoiMua As String, ByVal DiaChi As String) As Object
            Try
                Dim SQLHelper As New SQLDataHelper
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@LoaiPhi", LoaiPhi)
                SQLHelper.AddParameter("@BatDau", BatDau)
                SQLHelper.AddParameter("@KetThuc", KetThuc)
                SQLHelper.AddParameter("@TenNguoiMua", TenNguoiMua)
                SQLHelper.AddParameter("@DiaChi", DiaChi)
                Return SQLHelper.ExecuteScalar("spThongKeDoanhThu_KhachHang", CommandType.StoredProcedure)
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    End Class
End Namespace
